package com.example.demo.controller;

import com.example.demo.mapper.BookMapper;
import com.example.demo.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("book")
public class BookController {
    @Autowired
    BookMapper bookMapper;
    @GetMapping("/")
    List<Book> selectAll(){
        return bookMapper.selectAll();
    }
    @GetMapping("/selectById")
    Book selectById(int id){
        System.out.println(id);
        return bookMapper.selectById(id);
    }
    @GetMapping("/selectByName")
    List<Book> selectByName(String name){
        System.out.println(name);
        return bookMapper.selectByName(name);
    }
    @PostMapping("/add")
    String add(Book book){
        return bookMapper.add(book) == 1 ? "成功" : "失败" ;
    }
    @PostMapping("/updateById")
    String updateById(Book book){
        return bookMapper.updateById(book)== 1 ? "成功" : "失败" ;
    }
    @PostMapping("/delById")
    String delById(int id){
        return bookMapper.delById(id)== 1 ? "成功" : "失败";
    }
}
